#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <string.h>

typedef struct Stu {
	int age;
	char name[45];
}student;

void sys_err(const char *str){
	perror(str);
	exit(1);
}

void *tfn(void *arg){
	student *pstu;
	pstu = malloc(sizeof(pstu));
	pstu->age = 10;
	strcpy(pstu->name,"张三");
	sleep(5);
	printf("child end ,tid=%ld\n",pthread_self());
	return (void*)pstu;
}

int main(int argc, char *argv[]){
	pthread_t tid;
	student *pstu;

	int ret = pthread_create(&tid,NULL,tfn,NULL);
	if(ret != 0){
		sys_err("pthread_create error");
	}
	ret = pthread_join(tid,(void**)&pstu);//等待子线程返回
	if(ret !=0){
		sys_err("pthread_join error");
	}
	
	printf("child thread exit with  age=%d,name=%s\n",pstu->age,pstu->name);      free(pstu);
	
	pthread_exit((void*)0);
	
}


